package pages;

import org.openqa.selenium.By;
import utils.Log4Test;
import utils.WebDriverWrapper;

/**
 * Created by Vadim on 6/10/14.
 */
public class CompareProducts extends BasePage{
    private static final  String URL = "http://rozetka.com.ua/";
    protected final By compareProductDetails = By.name("comparison_details");
    protected final By compareProduct = By.name("tocomparison");
    protected final By addItem = By.className("add-item");

    public CompareProducts(WebDriverWrapper driver) {
        super(driver,URL);
    }

    public void open() {
        driver.get(URL);
    }

    public boolean addProductToComparison() {
        Log4Test.info("adding product to comparison");
        driver.findElement(compareProduct).click();
        return driver.findElement(compareProductDetails).isDisplayed();
    }

    public boolean compareProd(){
        try {
            driver.findElement(By.cssSelector(".lightblue.underline")).click();
            if (driver.findElement(addItem).isDisplayed()) {
                Log4Test.info("Products are compared");
            } return true;
        }catch (org.openqa.selenium.TimeoutException e) {
            Log4Test.warn("After timeout products not compared");
        }
        return false;
    }
}
